Quantopian's community platform is shutting down. Please read this post for more information and download your code.
Back to Community
Offline/ online ZipLine/ Quantopian --> How to detect in code?

Hi,

I am using PVTS since it is fully integrated with version control and has intellisense and much more. I want to move my Quantopian algos offline to Zipline since debugging is too harsh online. I am requesting help from Microsoft in getting a proper porting between offline/ online without making too much errors.

A suggestion is made to extract an variable out of Quantopian or offline to detect which code to execute. Is there such variable in Quantopian?

J

Post: http://pytools.codeplex.com/discussions/561096#post1289792

3 responses

This is an issue we are currently aware of and we're actively working to make it easier to port Zipline algos to Quantopian. The feature you described should be available soon!

Disclaimer

The material on this website is provided for informational purposes only and does not constitute an offer to sell, a solicitation to buy, or a recommendation or endorsement for any security or strategy, nor does it constitute an offer to provide investment advisory services by Quantopian. In addition, the material offers no opinion with respect to the suitability of any security or specific investment. No information contained herein should be regarded as a suggestion to engage in or refrain from any investment-related course of action as none of Quantopian nor any of its affiliates is undertaking to provide investment advice, act as an adviser to any plan or entity subject to the Employee Retirement Income Security Act of 1974, as amended, individual retirement account or individual retirement annuity, or give advice in a fiduciary capacity with respect to the materials presented herein. If you are an individual retirement or other investor, contact your financial advisor or other fiduciary unrelated to Quantopian about whether any given investment idea, strategy, product or service described herein may be appropriate for your circumstances. All investments involve risk, including loss of principal. Quantopian makes no guarantees as to the accuracy or completeness of the views expressed in the website. The views are subject to change, and may have become unreliable for various reasons, including changes in market conditions or economic circumstances.

Hmm..maybe you also fix that you do not overwrite common used namespaces:

get_datetime() seems to have a different meaning offline and online. It is quite prune to errors....to be honest. it is a VERY BAD coding practice. Without any meta type members like in C# with visibilty of overrides, hides, etc. you are simply not away that this function might mean something completely different in two environments.

I would advice to call such specific rewritten functions: qt_get_datatime() and have some library in which you declare with a compiler prefix if get_datetime() is based on the actual data parsed into handledata() or based on the systemtime.

Same for fetch_csv, what is the offline version of it? From Yahoo I get a Panel on bars, no idea what is returned in Quantopian (no watch to lookup).

Python seems to be a language prune to errors..keep all eyes open and code defensive...:-(.

    if not is_offline:  
        if not is_market_close(get_datetime()):  
            return  

When you say that get_datetime has a different meaning online vs offline, what is the offline comparision? The following algorithm may be copy/pasted between zipline and Quantopian for the same results:

from zipline.api import get_datetime, symbol


# Quantopian needs us to reference a security.  
initialize = lambda context: symbol('AAPL')


def handle_data(context, data):  
    print get_datetime()